/**
 * Source file: OnBlur_ClaimantStatment.ejs
 * Copyright (C) 2013 : Quantum Solutions
 * Id: $Id: OnBlur_ClaimantStatment.ejs 132 2013-05-14 16:10:34Z WillieVisagie55@gmail.com $
 * Date: $Date: 2013-05-14 16:10:34 +0000 (Tue, 14 May 2013) $
 */

var prevField = ""; 
function Field_onBlur(f) {
	prevField = f;
}

function Field_onFocus(f){
	//alert ("Field_onFocus:" + f.name );
	
	// only validate when we change fields
	// (ie can blur a field without leaving it! amazing! no!)
	if (f.name != prevField.name) {
		validateFields(prevField);
	}
}	

function validateFields(f) {
	 //alert("validateFields: "+f.name);

//Postal Code Validation X3
    if(f.name=="Code") {
		CheckPostal("Suburb","Code");
    } else if(f.name=="ADPACode_2") {
		CheckPostal("ADPASuburb_2","ADPACode_2");
    } else if(f.name=="Hospital_Address_Code") {
		CheckPostal("Hospital_Address_Suburb","Hospital_Address_Code");
	
// Idnumber Validations X2    
	} else if(f.name=="IDNumber") {
		if (!IDNoValidater(EFormGetValue("IDNumber")) && EFormGetValue("IDNumber") != ""){
			alert("Main member ID number is invalid: " + EFormGetValue("IDNumber"));				
			EFormSetFocus(EFormGetField("IDNumber"));  
		} 
    } else if(f.name=="BeneficiaryIDno_1") {
		if (!IDNoValidater(EFormGetValue("BeneficiaryIDno_1")) && EFormGetValue("BeneficiaryIDno_1") != ""){
			alert("Beneficiary ID number is invalid: " + EFormGetValue("BeneficiaryIDno_1"));				
			EFormSetFocus(EFormGetField("BeneficiaryIDno_1"));  
		} 
//Date Validations Should be X 11
	} else if (f.name=="Date_Policy_Issued_1") {
		if (!CheckDate(EFormGetValue("Date_Policy_Issued_1")) && EFormGetValue("Date_Policy_Issued_1") != ""){
			//alert("Invalid date: " + EFormGetValue("Date_Policy_Issued_1"));
			EFormSetFocus(EFormGetField("Date_Policy_Issued_1")); 
		}
	} else if (f.name=="Date_Policy_Issued_2") {
		if (!CheckDate(EFormGetValue("Date_Policy_Issued_2")) && EFormGetValue("Date_Policy_Issued_2") != ""){
			//alert("Invalid date: " + EFormGetValue("Date_Policy_Issued_2"));
			EFormSetFocus(EFormGetField("Date_Policy_Issued_2")); 
		}
	} else if (f.name=="Date_Policy_Issued_3") {
		if (!CheckDate(EFormGetValue("Date_Policy_Issued_3")) && EFormGetValue("Date_Policy_Issued_3") != ""){
			//alert("Invalid date: " + EFormGetValue("Date_Policy_Issued_3"));
			EFormSetFocus(EFormGetField("Date_Policy_Issued_3")); 
		}
	} else if (f.name=="Date_of_event") {
		if (!CheckDate(EFormGetValue("Date_of_event")) && EFormGetValue("Date_of_event") != ""){
			//alert("Invalid date: " + EFormGetValue("Date_of_event"));
			EFormSetFocus(EFormGetField("Date_of_event")); 
		}
	} else if (f.name=="Date_HA") {
		if (!CheckDate(EFormGetValue("Date_HA")) && EFormGetValue("Date_HA") != ""){
			//alert("Invalid date: " + EFormGetValue("Date_HA"));
			EFormSetFocus(EFormGetField("Date_HA")); 
		}
	} else if (f.name=="Date_CD") {
		if (!CheckDate(EFormGetValue("Date_CD")) && EFormGetValue("Date_CD") != ""){
			//alert("Invalid date: " + EFormGetValue("Date_CD"));
			EFormSetFocus(EFormGetField("Date_CD")); 
		}
	} else if (f.name=="DOA_1") {
		if (!CheckDate(EFormGetValue("DOA_1")) && EFormGetValue("DOA_1") != ""){
			//alert("Invalid date: " + EFormGetValue("DOA_1"));
			EFormSetFocus(EFormGetField("DOA_1")); 
		}
	} else if (f.name=="DOA_2") {
		if (!CheckDate(EFormGetValue("DOA_2")) && EFormGetValue("DOA_2") != ""){
			//alert("Invalid date: " + EFormGetValue("DOA_2"));
			EFormSetFocus(EFormGetField("DOA_2")); 
		}
	} else if (f.name=="DOA_3") {
		if (!CheckDate(EFormGetValue("DOA_3")) && EFormGetValue("DOA_3") != ""){
			//alert("Invalid date: " + EFormGetValue("DOA_3"));
			EFormSetFocus(EFormGetField("DOA_3")); 
		}
	} else if (f.name=="DOF") {
		if (!CheckDateNoFutureCheck(EFormGetValue("DOF")) && EFormGetValue("DOF") != ""){
			//alert("Invalid date: " + EFormGetValue("DOF"));
			EFormSetFocus(EFormGetField("DOF")); 
		}
	} else if (f.name=="DOD") {
		if (!CheckDate(EFormGetValue("DOD")) && EFormGetValue("DOD") != ""){
			//alert("Invalid date: " + EFormGetValue("DOD"));
			EFormSetFocus(EFormGetField("DOD")); 
		}	
// Telphone Numbers Should be X 7
	} else if(f.name=="Work_Number") {
		if (!TelNoValidater(EFormGetValue("Work_Number")) && EFormGetValue("Work_Number") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("Work_Number"));				
			EFormSetFocus(EFormGetField("Work_Number"));  
		} 
	} else if(f.name=="Cell_Number") {
		if (!TelNoValidater(EFormGetValue("Cell_Number")) && EFormGetValue("Cell_Number") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("Cell_Number"));				
			EFormSetFocus(EFormGetField("Cell_Number"));  
		} 
	} else if(f.name=="Home_Number") {
		if (!TelNoValidater(EFormGetValue("Home_Number")) && EFormGetValue("Home_Number") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("Home_Number"));				
			EFormSetFocus(EFormGetField("Home_Number"));  
		} 
	} else if(f.name=="ADTelWork_3") {
		if (!TelNoValidater(EFormGetValue("ADTelWork_3")) && EFormGetValue("ADTelWork_3") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("ADTelWork_3"));				
			EFormSetFocus(EFormGetField("ADTelWork_3"));  
		} 
	} else if(f.name=="FP_Tel") {
		if (!TelNoValidater(EFormGetValue("FP_Tel")) && EFormGetValue("FP_Tel") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("FP_Tel"));				
			EFormSetFocus(EFormGetField("FP_Tel"));  
		} 
	} else if(f.name=="ADCell_2") {
		if (!TelNoValidater(EFormGetValue("ADCell_2")) && EFormGetValue("ADCell_2") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("ADCell_2"));				
			EFormSetFocus(EFormGetField("ADCell_2"));  
		} 
	} else if(f.name=="ADTelHome_2") {
		if (!TelNoValidater(EFormGetValue("ADTelHome_2")) && EFormGetValue("ADTelHome_2") != ""){
			//alert("Work Telphone number is invalid: " + EFormGetValue("ADTelHome_2"));				
			EFormSetFocus(EFormGetField("ADTelHome_2"));  
		} 
//Validate Bank Details
	} else if(f.name=="DDAccountNumber") {		
		if (EFormGetValue("DDAccountNumber") != "") {
			AccNoValidatorNew("DDAccountNumber","DDTypeOfAccount","DDBranchCode","DDBankCode");
		} 		
	}	
	
    return true;
}